package com.iot.manager.ui.activities;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;

import androidx.appcompat.app.AppCompatActivity;

import com.iot.manager.R;
import com.iot.manager.data.models.UserManager;
import com.iot.manager.MainActivity;

public class SplashActivity extends AppCompatActivity {
    private static final long SPLASH_DELAY = 2000; // 2秒

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        // 初始化UserManager
        UserManager.init(getApplicationContext());
        
        setContentView(R.layout.activity_splash);

        new Handler(Looper.getMainLooper()).postDelayed(() -> {
            // 检查登录状态
            if (UserManager.getInstance().isLoggedIn()) {
                // 已登录，跳转到主界面
                startActivity(new Intent(SplashActivity.this, MainActivity.class));
            } else {
                // 未登录，跳转到登录界面
                startActivity(new Intent(SplashActivity.this, LoginActivity.class));
            }
            finish();
        }, SPLASH_DELAY);
    }
} 